#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


  int  bit,
       width,
	     x,
			 y;

  long posi,
       lof,
       ofs;

  word wid[16];
  byte raw[32],
	     data;


  FILE *tf,
       *cf;

int main( )
{
  tf = fopen( "c:/romhack/trans/free6/bin/8x8vwf_2.1bp","r+b");
  cf = fopen( "c:/romhack/trans/free6/bin/8x8vwf_2.wid","wb");

  if ( !tf || !cf) return -1;
  //
  fseek( tf, 0, SEEK_END );
  lof = ftell( tf );
  fseek( tf, 0, SEEK_SET );
  //
  posi    = 0;
  //
/*
  while( posi < lof )
  { //
    fread( raw, 1, 32, tf );
    posi += 32;

    for ( y = 0; y < 16; y++ )
		{ //
      wid[y] = (raw[y] << 8) + raw[y+0x10];

    }

    bit = 1;
    for ( x = 1; x < 16; x++ )
    {
      // 00000000 00000001
      if ( (wid[0] & bit) ) break;
      if ( (wid[1] & bit) ) break;
      if ( (wid[2] & bit) ) break;
      if ( (wid[3] & bit) ) break;
      if ( (wid[4] & bit) ) break;
      if ( (wid[5] & bit) ) break;
      if ( (wid[6] & bit) ) break;
      if ( (wid[7] & bit) ) break;

      if ( (wid[8] & bit) ) break;
      if ( (wid[9] & bit) ) break;
      if ( (wid[10] & bit) ) break;
      if ( (wid[11] & bit) ) break;
      if ( (wid[12] & bit) ) break;
      if ( (wid[13] & bit) ) break;
      if ( (wid[14] & bit) ) break;
      if ( (wid[15] & bit) ) break;
      //
      bit<<= 1;
    }

    //
    width = (16 - x);

    if ( width )
		{
      if ( width > 8 )
        fputc( 8, cf);
      else
        fputc( width + 2, cf);
      //
    }
		else
      fputc( 6, cf);


  }
*/
  while( posi < lof )
  { //
    fread( raw, 1, 8, tf );
    posi += 8;

    bit = 1;
    for ( x = 0; x < 8; x++ )
    {
      // 00000000 00000001
      if ( (raw[0] & bit) ) break;
      if ( (raw[1] & bit) ) break;
      if ( (raw[2] & bit) ) break;
      if ( (raw[3] & bit) ) break;
      if ( (raw[4] & bit) ) break;
      if ( (raw[5] & bit) ) break;
      if ( (raw[6] & bit) ) break;
      if ( (raw[7] & bit) ) break;
      //
      bit<<= 1;
    }

    //
    width = (8 - x);

    if ( width > 0 )
		{
      if ( width >= 8 )
        fputc( 8, cf);
      else
        fputc( width + 1, cf);
      //
    }
		else
      fputc( 4, cf);


  }


  fcloseall( );
  return 0;
}

